package com.hqyj.springcloud.handler;

import com.hqyj.springcloud.pojo.Order;
import com.hqyj.springcloud.pojo.RestfulEntity;
import com.hqyj.springcloud.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OrderHandler {
    @Autowired
    private OrderService orderService;

    @PostMapping(value = "app02")
    public @ResponseBody RestfulEntity appendOrder(@RequestBody Order order){
        boolean add = orderService.add(order);
        RestfulEntity restfulEntity = new RestfulEntity();
        if (add) {
            restfulEntity.setCode(200);
            restfulEntity.setMessage("下单成功");
        } else {
            restfulEntity.setCode(100);
            restfulEntity.setMessage("下单失败");
        }
        return restfulEntity;
    }
}
